import { NestFactory } from '@nestjs/core'
import { AppModule } from './app.module'
import { TransformInterceptor } from './common/interceptors/transform.interceptor'

async function bootstrap() {
  const app = await NestFactory.create(AppModule)

  // 应用全局拦截器
  app.useGlobalInterceptors(new TransformInterceptor())

  // 设置跨域请求
  app.enableCors({
    origin: ['http://127.0.0.1:5173', 'http://localhost:5173'],
    methods: 'GET,HEAD,PUT,PATCH,POST,DELETE,OPTIONS',
    credentials: true, // 允许发送Cookie
    allowedHeaders: 'Origin,X-Requested-With,Content-Type,Accept,Authorization'
  })

  app.setGlobalPrefix('api')

  await app.listen(process.env.PORT ?? 8080)
}
bootstrap()
